import {Component, OnInit, ViewContainerRef} from '@angular/core';
import {CallcenterService} from "../../services/callcenter.service";

import {Router} from "@angular/router";
import {NzModalService} from "ng-zorro-antd/modal";
import {CustomerloginComponent} from "./components/customerlogin/customerlogin.component";
import {AlertService} from "../../services/alert.service";
import {AdminloginComponent} from "./components/adminlogin/adminlogin.component";


@Component({
  selector: 'app-welcome',
  templateUrl: './welcome.component.html',
  styleUrls: ['./welcome.component.css']
})
export class WelcomeComponent implements OnInit {


  constructor(private callservice:CallcenterService
  ,private router:Router,private modal: NzModalService, private viewContainerRef: ViewContainerRef
  ,private alertservice:AlertService) {

  }

  ngOnInit() {

  }


  conect(){
   //this.callservice.wsSubject
  //console.dir(this.callservice.wsSubject);
  //   this.callservice.init()
  //     .then((flag:boolean)=>{
  //       if(flag==true){
  //         this.router.navigate(['/welcome/chatroom'])
  //       }
  //       else {
  //         alert('连接错误')
  //       }
  //     })
    this.router.navigate(['/welcome/chatroom'])


  }



  customerlogin(){

    const modalwindow= this.modal.create({
      nzTitle: '客户登录',
      nzContent: CustomerloginComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzComponentParams: {

      },

      nzOnOk:()=>new Promise(resolve => {
        // modalwindow.getContentComponent().save();

        let temp=modalwindow.getContentComponent().customloginform;
        if(!temp.cell){
        this.alertservice.showWarning('请输入你的手机号！')
          resolve(false);
        }
        else {

          modalwindow.getContentComponent().login();

          setTimeout(()=>{

            resolve(true);
            //this.getEmpDetailByEmpid(this.empid);
            //this.loadEmpImg();
          }, 2000)

        }
      }
        )
    });
    modalwindow.afterClose
      .subscribe(((reason:string)=>{
        console.log(reason);
        if(reason=='ok'){
          this.router.navigate(['/customer'])
        }
        else {
          this.alertservice.showError('登录错误，请重试');
        }


      }))


  }


  adminLogin(){
    const modalwindow= this.modal.create({
      nzTitle: '管理员登录',
      nzContent: AdminloginComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzComponentParams: {

      },

      nzOnOk:()=>new Promise(resolve => {
          // modalwindow.getContentComponent().save();
            let temp=modalwindow.getContentComponent().f;
            if(!temp.cell){
              resolve(false);
            }
            else {
              modalwindow.getContentComponent().login();
              resolve(false);
            }

        }
      )
    });
    modalwindow.afterClose
      .subscribe(((reason:string)=>{
        console.log(reason);
        if(reason=='ok'){
          this.router.navigate(['/callcenter'])
        }
        else {
          this.alertservice.showError('登录错误，请重试');
        }


      }))
  }







}
